#ifndef _BA_H
#define _BA_H
/*
  author Sylvain Bertrand <digital.ragnarok@gmail.com>
  Protected by GNU Affero GPL v3 with some exceptions.
  See README at root of alga tree.
*/
#define BA_ERR 950

enum ba_map_type {
	BA_MAP_COHERENT_CONTIG
};

struct ba_map {
	struct list_head n;
	enum ba_map_type type;

	struct ctx *ctx;
	u64 ptes_start;		/* location of the pte table in (v)ram */
	unsigned gpu_ps_n;

	void *cpu_addr;
	dma_addr_t bus_addr;
	u64 gpu_addr;
};

struct ctx {
	struct pci_dev *dev;

	struct rng mng;		/* range manager of the aperture */
	u64 pt_start;		/* location of the page table in (v)ram */

	struct list_head maps;
};

struct ba {
	dma_addr_t dummy_bus_addr;
	void *dummy_cpu_addr;

	struct ba_map *wb_map;
	struct ba_map *ih_ring_map;
	struct ba_map *cp_ring_map;

	struct ctx ctx0;
};

/* major bus aperture functions */
int ba_init(struct pci_dev *dev);
int ba_map(struct pci_dev *dev);
void ba_unmap(struct pci_dev *dev);
void ba_shutdown(struct pci_dev *dev);
#endif /* _BA_H */
